package com.example.bzh.gamecat.ui.society;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.bzh.gamecat.R;
import com.example.bzh.gamecat.bean.GameListBean;
import com.example.bzh.gamecat.ui.society.allsociety.AllSocietyActivity;
import com.example.bzh.gamecat.util.RoundImageUtil;

import java.util.List;

/**
 * Created by MyPC on 2016/8/15.
 */
public class GameGridAdapter extends BaseAdapter {
    private List<GameListBean> gameListBeens;
    private Context context;
    public GameGridAdapter(List<GameListBean> gameListBeens, Context context){
        this.gameListBeens = gameListBeens;
        this.context = context;
    }
    @Override
    public int getCount() {
        return gameListBeens.size();
    }

    @Override
    public Object getItem(int i) {
        return gameListBeens.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.grid_item_society,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        final GameListBean gameListBean = gameListBeens.get(position);

        //绑定数据
        holder.tvName.setText(gameListBean.getGameName());
        holder.tvNum.setText(gameListBean.getNum()+"个公会");
        Glide.with(viewGroup.getContext()).load(gameListBean.getIcon()).transform(new RoundImageUtil.GlideRoundTransform(context,5)).into(holder.ivLogo);

        holder.ivLogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AllSocietyActivity.class);
//                intent.putExtra("type","play");
                context.startActivity(intent);
            }
        });

        holder.ivLogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,AllSocietyActivity.class);
                intent.putExtra("ID",String.valueOf(gameListBean.getMId()));
                Log.i("TAG","id=========="+gameListBean.getMId());
                context.startActivity(intent);

            }
        });

        return view;
    }

    class ViewHolder{
        private ImageView ivLogo;
        private TextView tvName,tvNum;
        public ViewHolder(View view){
            ivLogo = (ImageView) view.findViewById(R.id.image_logo_grid);
            tvName = (TextView) view.findViewById(R.id.text_name_grid);
            tvNum = (TextView) view.findViewById(R.id.text_num_grid);
        }

    }

}
